
package com.ffcs.crmd.tsp.admin.facade.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ctg.itrdc.platform.common.entity.PageInfo;
import com.ctg.itrdc.platform.common.utils.bean.BeanUtils;
import com.ffcs.crmd.platform.core.ddd.facade.impl.AbstractCrmDomFacade;
import com.ffcs.crmd.tsp.admin.api.dto.SliceDTO;
import com.ffcs.crmd.tsp.admin.api.facade.ISliceFacade;
import com.ffcs.crmd.tsp.admin.entity.Slice;
import com.ffcs.crmd.tsp.admin.service.ISliceService;

@Service("sliceFacade")
public class SliceFacadeImpl extends AbstractCrmDomFacade implements ISliceFacade {
   	
   	@Autowired
	private ISliceService sliceService;
	   
   	private PageInfo<SliceDTO> copyPageInfo(PageInfo<Slice> pageInfo) throws Exception{
        PageInfo<SliceDTO> pageInfoDto = new PageInfo<SliceDTO>();
        BeanUtils.applyIf(pageInfoDto, pageInfo, false);
        pageInfoDto.setList(BeanUtils.copyList(pageInfo.getList(), SliceDTO.class));
        return pageInfoDto;
    }
   	
	@Override
    public SliceDTO get(SliceDTO sliceDto) throws Exception {
       	 Slice slice = new Slice();
         BeanUtils.applyIf(slice, sliceDto, false);
     
        Slice rslice = sliceService.get(slice);
        SliceDTO rsliceDTO = new SliceDTO();
        BeanUtils.applyIf(rsliceDTO, rslice, false);
        return rsliceDTO;
    }
    
    /**
     * 功能说明:
     * 
     * @param clusterName
     * @param sliceGroupId
     * @param skey
     * @return
     * @throws Exception
     */
    @Override
    public List<SliceDTO> query(SliceDTO sliceDto) throws Exception {
        Slice slice = new Slice();
        BeanUtils.applyIf(slice, sliceDto, false);
        
        List<Slice> sliceList = sliceService.query(slice);
        return BeanUtils.copyList(sliceList, SliceDTO.class);
    }
    
    /**
     * 功能说明:
     * 
     * @param clusterName
     * @param sliceGroupId
     * @param skey
     * @param pageNumber
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<SliceDTO> queryPage(SliceDTO sliceDto) throws Exception {
        Slice slice = new Slice();
        BeanUtils.applyIf(slice, sliceDto, false);
        
        PageInfo<Slice> pageInfo = sliceService.queryPage(slice, sliceDto.getPageNumber(), sliceDto.getPageSize());
        return copyPageInfo(pageInfo);
    }
    
    @Override
    public void remove(List<SliceDTO> sliceDtoList) throws Exception {
        List<Slice> sliceList = BeanUtils.copyList(sliceDtoList, Slice.class);
        sliceService.deleteSlice(sliceList);
    }
    
    
    @Override
    public void remove(SliceDTO sliceDto) throws Exception {
        Slice slice = new Slice();
        BeanUtils.applyIf(slice, sliceDto, false);
        sliceService.deleteSlice(slice);
    }

    @Override
    public void save(SliceDTO sliceDto) throws Exception {
        Slice slice = new Slice();
        BeanUtils.applyIf(slice, sliceDto, false);
        sliceService.saveSlice(slice);
    }



    @Override
    public void update(SliceDTO sliceDto) throws Exception {
        Slice slice = new Slice();
        BeanUtils.applyIf(slice, sliceDto, false);
        sliceService.updateSlice(slice);
    }
}
